//
//  LKBoTongFeedbackWebViewController+PictureBrowser.m
//  iOS-BTong-ApplicationCenter
//
//  Created by Eric MiAo on 2018/5/23.
//  Copyright © 2018年 毛毛驴. All rights reserved.
//

#import "LKBoTongFeedbackWebViewController+PictureBrowser.h"
#import "XLPhotoBrowser.h"

@implementation LKBoTongFeedbackWebViewController (PictureBrowser)
NSString *BotongApplicationCenterPictureBrowserJSHandler = @"BotongApplicationCenterPictureBrowserJSHandler";

- (void)scriptPictureBrowserMessage:(WKScriptMessage *)message {
    if ([message.name isEqualToString:BotongApplicationCenterPictureBrowserJSHandler]) {
        
        NSDictionary *params = message.body[scriptParams];
        if (!params || ![params isKindOfClass:[NSDictionary class]]) {
            return;
        }
        if ([params objectForKey:@"imageArray"] && [[params objectForKey:@"imageArray"] isKindOfClass:NSClassFromString(@"NSArray")] && [params objectForKey:@"currentCount"]) {
            
            NSArray *tempArray = [params objectForKey:@"imageArray"];
            NSMutableArray *imageArrayM = [NSMutableArray array];
            for (int i = 0; i < tempArray.count; i ++) {
                NSString *url = [[tempArray objectAtIndex:i] objectForKey:@"img"];
                [imageArrayM addObject:url];
            }
            
            XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithImages:imageArrayM currentImageIndex:[[params objectForKey:@"currentCount"] integerValue]];
            browser.browserStyle = XLPhotoBrowserStyleIndexLabel; // 微博样式
        }
    }
}


@end
